package com.unitTest;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JUnit4Mockery;
import org.jmock.lib.legacy.ClassImposteriser;
import org.joda.time.DateTime;
import org.junit.Test;

import com.acmetelecom.Call;
import com.acmetelecom.CallEnd;
import com.acmetelecom.CallStart;

public class CallTest {	
	
	Mockery context = new JUnit4Mockery(){{
		setImposteriser(ClassImposteriser.INSTANCE);
	}};
	CallStart start = context.mock(CallStart.class);
	CallEnd end = context.mock(CallEnd.class);

	@Test
	public void testDurationSeconds() {
		final DateTime dt = new DateTime("2011-11-26T16:20:00");
		context.checking(new Expectations(){{
			allowing (start).time(); will(returnValue(dt));
			allowing (end).time(); will(returnValue(dt.plusSeconds(10)));
		}});
		
		Call call = new Call(start,end);
		int duration = call.durationSeconds();
		assertEquals(10, duration);
	}
	
	@Test
	public void testDate(){
		final DateTime dt = new DateTime("2011-11-26T16:20:00");
		context.checking(new Expectations(){{
			allowing (start).time(); will(returnValue(dt));
			allowing (end).time(); will(returnValue(dt.plusSeconds(10)));
		}});
		
		Call call = new Call(start,end);
		assertTrue(dt.toString().equals(call.date()));
	}
	
	@Test
	public void testPeakandOffPeakDuration(){
		final DateTime dt = new DateTime("2011-11-26T6:59:50");
		context.checking(new Expectations(){{
			allowing (start).time(); will(returnValue(dt));
			allowing (end).time(); will(returnValue(dt.plusSeconds(30)));
		}});
		
		Call call = new Call(start,end);
		int peakDuration = call.peakDurationSeconds();
		int offPeakDuration = call.offpeakDurationSeconds();
		assertEquals(10, offPeakDuration);
		assertEquals(20, peakDuration);	
	}

	
}
